﻿﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartApplication.Api.Applient.Command.Feed;
using SmartApplication.Api.Dto;
using SmartApplication.ApiCode;

namespace SmartApplication.Api.Controllers
{
    /// <summary>
    /// 养殖控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FeedController : ControllerBase
    {
        public FeedController(IMediator mediator)
        {
            Mediator = mediator;
        }

        public IMediator Mediator { get; }

        /// <summary>
        /// 显示养殖详细信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<FeedDto>>> ListFeed([FromQuery] ListFeedCommand request)
        {
            return await Mediator.Send(request);
        }

        /// <summary>
        /// 添加养殖信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddFeed(AddFeedCommand request)
        {
            return await Mediator.Send(request);
        }

        /// <summary>
        /// 修改养殖信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateFeed(UpdateFeedCommand request)
        {
            return await Mediator.Send(request);
        }

        /// <summary>
        /// 显示养殖公司信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<CompaniesDto>>> ListCompanies([FromQuery]ListCompaniesCommand request)
        {
            return await Mediator.Send(request);
        }

        /// <summary>
        /// 显示所有养殖企业信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<CompaniesDto>>> GetAllCompanies([FromQuery]GetAllCompaniesCommand request)
        {
            return await Mediator.Send(request);
        }

        /// <summary>
        /// 修改养殖企业信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateCompanies(UpdateCompaniesCommand request)
        {
            return await Mediator.Send(request);
        }

        /// <summary>
        /// 显示保健信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<HealthDto>>> ListHealth([FromQuery]ListHealthCommand request)
        {
            return await Mediator.Send(request);
        }


        /// <summary>
        /// 添加保健信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddHealth(AddHealthCommand request)
        {
            return await Mediator.Send(request);
        }


        /// <summary>
        /// 修改保健信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateHealth(UpdateHealthCommand request)
        {
            return await Mediator.Send(request);
        }

        ///<summary>
        /// 保健信息逻辑删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DeleteHealth(DeleteHealthCommand request)
        {
            return await Mediator.Send(request);
        }
    }
}
